home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / SRC / HOARDDLL.ZIP / 3rdParty / hoard / libhoard-2.0.2 / wrapper.h < prev   
Encoding:
C/C++ Source or Header  |  2002-06-18  |  2.4 KB  |  78 lines

  1. ///-*-C++-*-//////////////////////////////////////////////////////////////////
  2. //
  3. // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
  4. //        for Shared-Memory Multiprocessors
  5. // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
  6. //
  7. // Copyright (c) 1998-2000, The University of Texas at Austin.
  8. //
  9. // This library is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU Library General Public License as
  11. // published by the Free Software Foundation, http://www.fsf.org.
  12. //
  13. // This library is distributed in the hope that it will be useful, but
  14. // WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. //////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Note: This file was modified by Crystal Decisions in June 2002.
  24. //
  25. //////////////////////////////////////////////////////////////////////////////
  26.  
  27.  
  28. #ifndef _WRAPPER_H_
  29. #define _WRAPPER_H_
  30.  
  31. #include "arch-specific.h"
  32. #include "config.h"
  33. #include "processheap.h"
  34.  
  35. class wrapper {
  36. public:
  37.   wrapper (void) {
  38.     hoardLockInit(_lock);
  39.   }
  40.  
  41.   // Return the process heap.  We can't just have a static
  42.   // processHeap, because on some systems this causes problems (e.g.,
  43.   // its destructor is registered by atexit(), which in turn calls
  44.   // malloc()...)  Instantiating the processHeap inside of a buffer of
  45.   // characters avoids this problem, since the destructor won't be
  46.   // added to atexit() at init time.
  47.   processHeap * TheAllocator (void) {
  48.     static int initialized = 0;
  49.     if (!initialized) {
  50.       hoardLock (_lock);
  51.       if (!initialized) {
  52.         buf = (char *) hoardSbrk(sizeof(processHeap));
  53.         TheRealAllocator = new (buf) processHeap;
  54.         initialized = 1;
  55.       }
  56.       hoardUnlock (_lock);
  57.     }
  58.     return TheRealAllocator;
  59.   }
  60.  
  61. #if !defined(CRYSTAL_HOARD)
  62.   // This destructor causes some problems if the Hoard is LD_PRELOAD'd into sh on Solaris 7.
  63.   // Since it does nothing useful, get rid of it.
  64.   ~wrapper (void) {
  65.     TheRealAllocator->stats();
  66.   }
  67. #endif
  68.  
  69. private:
  70.   static char * buf;
  71.   static processHeap * TheRealAllocator;
  72.   static hoardLockType _lock;
  73. };
  74.  
  75.  
  76. #endif // _WRAPPER_H_
  77.  
  78.